from sqlalchemy import Column, DateTime, Integer, String, BigInteger, CHAR
from sqlalchemy.sql import func
from base import Base
from sqlalchemy.orm import relationship

class SysPost(Base):
    __tablename__ = 'sys_posts'

    id = Column(BigInteger, primary_key=True, autoincrement=True, comment='岗位ID')
    post_code = Column(String(64), nullable=False, comment='岗位编码')
    post_name = Column(String(50), nullable=False, comment='岗位名称')
    post_sort = Column(Integer, nullable=False, comment='显示顺序')
    status = Column(CHAR(1), nullable=False, comment='状态（0正常 1停用）')
    create_by = Column(String(64), default='', comment='创建者')
    created_at = Column(DateTime, default=func.now(), comment='创建时间')
    update_by = Column(String(64), default='', comment='更新者')
    updated_at = Column(DateTime, onupdate=func.now(), comment='更新时间')
    deleted_at = Column(DateTime, nullable=True, comment='删除时间')
    remark = Column(String(500), nullable=True, comment='备注')

    users = relationship('SysUser', secondary='sys_user_posts', back_populates='posts')

    def __repr__(self):
        return f"<SysPost(post_id={self.id}, post_name={self.post_name})>"
